<template>
  <div>
    <template>
      <Card style="width:850px;margin: auto;">
        <Form :model="formLeft" label-position="left" :rules="validateLibForm" :label-width="100" style="width: 300px;margin: auto;">

        <FormItem label="设备类型"  prop="category">
            <Input v-model="formLeft.category" maxlength="10"></Input>
          </FormItem>

          <row type="flex" justify="center">
            </i-col>
            <i-col span="30">
              <Button type="primary"  @click="DeviceCategoryUpdateById">修改</Button>
              <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
            </i-col>
          </row>

        </Form>
      </Card>
    </template>
  </div>
</template>

<script>
  import {DeviceCategoryFindByCategory,DeviceCategoryUpdateById} from "../../../api/data"

  export default {
    data() {
      return {
        formLeft: {
          id:'',
          category: '',
        },
        validateLibForm: {
          category: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        }
      }
    },
    mounted() {
      const categoryFlag = this.$route.query.category;
      if(categoryFlag){
        this.formLeft.category = categoryFlag;
        this.DeviceCategoryFindByCategory();
      }
    },
    methods: {
      DeviceCategoryUpdateById(){
        if (
          this.formLeft.category !== null && this.formLeft.category !== ""){
          DeviceCategoryUpdateById(this.formLeft).then(res => {
            this.$Message.success("编辑成功");
            this.$router.go(-1)
          })
        }else {
          this.$Message.error("设备类型不能为空！！！")
        }
      },
      back(){
        this.$router.go(-1);
      },
      DeviceCategoryFindByCategory(){
        var data =  {
          category:this.formLeft.category,
        }
        DeviceCategoryFindByCategory(data).then(res => {
          //console.log( res.data.data)
          this.formLeft = res.data.data;
        })
      }
    },

  }
</script>


